Removing Pages Based on Condition from Page List in Pega
In real Pega projects, iterating over Page Lists is something you do almost daily — to read data, apply validations, or update records. However, the moment the requirement changes to removing pages from a Page List based on a condition, things often go wrong. I’ve seen many entry-level developers get stuck here. Let’s break down the clean and Pega-recommended way to handle this scenario.
Understanding the Problem
A Page List is an ordered collection of pages, for example:
- .Participants()
.Transactions()
Each page usually represents a business entity.
Now imagine a requirement like:
Remove participants whose Age < 18
Remove transactions where Amount = 0
This is where conditional removal becomes important.
❌ Common Mistake (Don’t Do This)
Many developers try to remove pages while looping forward through the Page List.
Example:
Loop from index 1 → N
Remove page at index 2
Index shifts → next page gets skipped
This leads to:
Skipped records
Partial cleanup
Hard-to-debug issues
👉 Never modify a Page List while iterating forward through it.
✅ Recommended Approach
Using Data Transform to Iterate Over a Page List and Modify Items
-
Loop over the Page List in your Data Transform.
-
Inside the loop, apply a When condition based on which you want to delete the item.
-
When the condition evaluates to true, set
.pyDeletedObject = trueon the current page. -
After the loop completes, add a final step to call the
RemoveDeletedObjectsfunction, passing the Page List name as its parameter.
check below example:
1) You can always search for the function in the Expression Builder to better understand its parameters and definition.
2) In the example below,
I have modified an existing Page List (ParticipantList) that contains participants of all ages. The requirement is to remove all participants whose age is below 18. Check out the code below
“Pega’s internal page list iterator can become unstable if pages are removed during forward traversal. Setting .pyDeletedObject=true and calling RemoveDeletedObjects() ensures the engine safely purges pages after iteration.”


Comments
Post a Comment